self.addEventListener('fetch', (event) => {
  if (event.request.url.endsWith('/mock/upload')) {
    event.respondWith(
      (async () => {
        await new Promise((resolve) => {
          setTimeout(() => {
            resolve();
          }, 4000);
        });
        return new Response(JSON.stringify({
          success: true
        }), {
          headers: {
            'Content-type': 'application/json'
          }
        });
      })()
    );

  } else {
    event.respondWith(caches.match(event.request).then((response) => {
      return response || fetch(event.request);
    }));
  }
});
